﻿//-----------------------------------------------------------------------
// <copyright company="www.3WayWebdesign.de">
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//
// <author>Michael Morbach</author>
// <email>Michael@3waywebdesign.de</email>
// <web>http://www.3waywebdesign.de</web>
//-----------------------------------------------------------------------

namespace Tww.MAF.MAFMenuBarModule.Models.UI.Menu
{
    #region Imports

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Tww.MAF.MAFInfrastructure.Models.UI.Menu;


    #endregion

    public class MenuTreeEntry : IMenuTreeEntry
    {
        #region Private Fields

        private string activeIconURI = string.Empty;
        private string inactiveIconURI = string.Empty;

        #endregion

        #region Ctors

        public MenuTreeEntry()
        {
            this.Children = new List<IMenuTreeEntry>();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the Title of this Entry
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the URL for an icon of this Entry
        /// </summary>
        public string ImageURL { get; set; }

        /// <summary>
        /// Gets the Parentnode of this Entry
        /// </summary>
        public IMenuTreeEntry Parent { get; private set; }

        /// <summary>
        /// Gets a List of Childnodes of this Entry
        /// </summary>
        public List<IMenuTreeEntry> Children { get; private set; }

        /// <summary>
        /// Gets or sets the ranking for this Entry
        /// </summary>
        public int Ranking { get; set; }

        /// <summary>
        /// Gets or sets the Icon of an Active Entry
        /// </summary>
        public ImageSource ActiveIconSource { get; private set; }

        /// <summary>
        /// Gets or sets the Icon of an InActive Entry
        /// </summary>
        public ImageSource InActiveIconSource { get; private set; }

        /// <summary>
        /// Gets or sets the URI of the Icon of an Active Entry
        /// </summary>
        public string ActiveIconURI
        {
            get
            {
                return this.activeIconURI;
            }
            set
            {
                this.activeIconURI = value;
                this.ActiveIconSource = new BitmapImage( new Uri( value, UriKind.RelativeOrAbsolute ) );
            }
        }

        /// <summary>
        /// Gets or sets the URI of the Icon of an InActive Entry
        /// </summary>
        public string InActiveIconURI
        {
            get
            {
                return this.inactiveIconURI;
            }
            set
            {
                this.inactiveIconURI = value;
                this.InActiveIconSource = new BitmapImage( new Uri( value, UriKind.RelativeOrAbsolute ) );
            }
        }

        #endregion

        #region Private Properties

        #endregion

        #region Public Methods

        /// <summary>
        /// Attaches the specified this node to another Node
        /// </summary>
        /// <param name="entry">Node where this node should be attached</param>
        public void AttachTo( IMenuTreeEntry entry )
        {
            if ( this.Parent != null )
            {
                this.DetachFrom( this.Parent );
            }

            entry.Children.Add( this );
            this.Parent = entry;
        }

        /// <summary>
        /// Detaches the specified Node from this Node
        /// </summary>
        /// <param name="entry">Entry to detach</param>
        public void DetachFrom( IMenuTreeEntry entry )
        {
            if ( entry.Children.Contains( this ) )
            {
                this.Parent.Children.Remove( this );
                this.Parent = null;
            }
        }

        /// <summary>
        /// Disbands this Node from the Rest of the structure
        /// </summary>
        public void Disband()
        {
            if ( this.Parent != null )
            {
                this.DetachFrom( this );
            }

            this.Children.ForEach( c => c.Disband() );
        }

        #endregion

        #region Private Methods

        #endregion

        #region Events

        #endregion














        
    }
}
